package com.jbit.redis.utils;

import org.springframework.data.redis.core.RedisTemplate;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

public class RedisUtils {
    @Resource
    private RedisTemplate redisTemplate;

    public Object get(String key){
        return redisTemplate.opsForValue().get(key);
    }

    public void set(String key,Object value){
        redisTemplate.opsForValue().set(key,value);
    }
    /**
     * 过期时间单位是秒
     * @param key
     * @param value
     * @param expire
     */
    public void set(String key,Object value, Long expire){
        redisTemplate.opsForValue().set(key,value,expire, TimeUnit.SECONDS);
    }
    public boolean hasKey(String key){
        return redisTemplate.hasKey(key);
    }

    public Boolean deleteKey(String key){
        return redisTemplate.delete(key);
    }

}
